﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Destex
{
    public partial class KesilenSiparisler : XForm
    {
        public KesilenSiparisler()
        {
            InitializeComponent();
        }

        private void KesilenKumaslar_Load(object sender, EventArgs e)
        {
            gvKesilenKumas.Init("DX_GetKesilenKumas");

            gvKesilenKumas.SetCaptions("UserId:Kesen");

            gvKesilenKumas.FormatAsNumber(2, "BirimAlisFiyat", "AlisTutar", "BirimSatisFiyat", "SatisTutar");
            gvKesilenKumas.FormatAsNumber(1, "KesilenQty");
            gvKesilenKumas.AddSummary("KesilenQty", "BirimAlisFiyat", "AlisTutar", "BirimSatisFiyat", "SatisTutar");

            gvKesilenKumas.RowCellStyle += gvKesilenKumas_RowCellStyle;
            bbiGuncelle.ItemClick += bbiGuncelle_ItemClick;

            gvKesilenKumas.MakeReadOnly();
            gvKesilenKumas.BestFitColumns();
        }

        void gvKesilenKumas_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                if (e.Column.FieldName == "PRO")
                {
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    e.Appearance.ForeColor = Color.Green;
                }
                else if (e.Column.FieldName == "KesilenMetraj")
                {
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                }
                else if (e.Column.FieldName == "AlisTutar")
                {
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                }
                else if (e.Column.FieldName == "SatisTutar")
                {
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    e.Appearance.ForeColor = Color.Red;
                }
            }
        }

        private void bbiGuncelle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvKesilenKumas.RefreshDataSource("DX_GetKesilenKumas");
            gvKesilenKumas.BestFitColumns();
        }
    }
}
